﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:text="clr-namespace:WhiteFlow.Wpf.Controls.Text;assembly=WhiteFlow.Wpf.Controls">

    <Style x:Key="AutoCompleteItemStyle" TargetType="{x:Type ListBoxItem}">
        <Setter Property="Padding" Value="3" />
        <Setter Property="HorizontalContentAlignment" Value="Left" />
        <Setter Property="VerticalContentAlignment" Value="Top" />
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="FocusVisualStyle" Value="{x:Null}" />
        
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ListBoxItem}">
                    <Grid Background="{TemplateBinding Background}">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal" />
                                <VisualState x:Name="MouseOver">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="fillColor" Storyboard.TargetProperty="Opacity" Duration="0" To=".35"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="contentPresenter" Storyboard.TargetProperty="Opacity" Duration="0" To=".55" />
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="SelectionStates">
                                <VisualState x:Name="Unselected"/>
                                <VisualState x:Name="Selected">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="fillColor2" Storyboard.TargetProperty="Opacity" Duration="0" To=".5"/>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="FocusStates">
                                <VisualState x:Name="Focused">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="FocusVisualElement" Storyboard.TargetProperty="Visibility" Duration="0">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Unfocused">
                                    <Storyboard>
                                        <ColorAnimation Storyboard.TargetName="fillColor2" Storyboard.TargetProperty="Fill.Color" Duration="0" To="#FFF0F0F0" />
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        
                        <Rectangle x:Name="fillColor" Opacity="0" Fill="#FFBADDE9" IsHitTestVisible="False" RadiusX="1" RadiusY="1"/>
                        <Rectangle x:Name="fillColor2" Opacity="0" Fill="#FFBADDE9" IsHitTestVisible="False" RadiusX="1" RadiusY="1"/>
                        
                        <ContentPresenter x:Name="contentPresenter"
                                          Content="{TemplateBinding Content}"
                                          ContentTemplate="{TemplateBinding ContentTemplate}"
                                          HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                          Margin="{TemplateBinding Padding}"/>
                        
                        <Rectangle x:Name="FocusVisualElement" Stroke="#FF6DBDD1" StrokeThickness="1" Visibility="Collapsed" RadiusX="1" RadiusY="1" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type text:AutoCompleteTextBox}">
        <Setter Property="Background" Value="White" />
        
        <Setter Property="Control.Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type text:AutoCompleteTextBox}">
                    <Border FocusManager.FocusedElement="{Binding ElementName=PART_tbText}"
                            Background="{TemplateBinding Background}">
                        <DockPanel LastChildFill="True">
                            <TextBox Name="PART_tbText" 
                                     DockPanel.Dock="Top"
                                     Text="{Binding Path=SelectedItem, Mode=TwoWay, RelativeSource={RelativeSource Mode=TemplatedParent}}" 
                                     Padding="0" 
                                     VerticalAlignment="Center" 
                                     BorderBrush="{TemplateBinding BorderBrush}" 
                                     FontSize="{TemplateBinding FontSize}"
                                     FontFamily="{TemplateBinding FontFamily}"
                                     Background="{TemplateBinding Background}" />

                            <Popup Name="PART_autoCompletionItemsPopup"
                                   PopupAnimation="Fade"
                                   IsOpen="False" 
                                   StaysOpen="False" 
                                   PlacementTarget="{Binding ElementName=PART_tbText}"
                                   Placement="Bottom"
                                   MinWidth="{Binding ElementName=PART_tbText, Path=ActualWidth}"
                                   MaxHeight="{Binding Path=PopupMaxHeight, Mode=OneWay, RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                   AllowsTransparency="True">
                                <Border Background="{TemplateBinding Background}" 
                                        BorderBrush="LightGray" 
                                        BorderThickness="1">
                                    <ScrollViewer Padding="2,0,2,0" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
                                        <ListBox Name="PART_autoCompletionItemsList" 
                                                 ItemsSource="{Binding Path=AutoCompletionFilteredListSource, RelativeSource={RelativeSource Mode=TemplatedParent}}" 
                                                 ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                                                 BorderBrush="Transparent" 
                                                 FontSize="{TemplateBinding FontSize}"
                                                 FontFamily="{TemplateBinding FontFamily}"
                                                 ItemContainerStyle="{StaticResource ResourceKey=AutoCompleteItemStyle}" />
                                    </ScrollViewer>
                                </Border>
                            </Popup>
                        </DockPanel>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>